<template>
  <div>
    <el-button class="menu_icon iconfont icon-icon_look action_color1" size="mini" @click="detail(row)">&nbsp;查看</el-button>
    <el-button v-if="show(2)" class="menu_icon iconfont icon-xiugai-copy action_color1" size="mini" @click="edit(row)">&nbsp;修改</el-button>
    <el-button v-if="show(3)" class="menu_icon iconfont icon-shenpi action_color1" size="mini" @click="approve(row)">&nbsp;{{row.taskKey === 'UserTask_1sci9cl' ? '处理' : '审批'}}</el-button>
    <el-button v-if="show(4)" class="menu_icon iconfont icon-shanchu action_color2" size="mini" @click="del(row)">&nbsp;删除</el-button>
  </div>
</template>

<script>
import store from '@/store'
export default {
  name: 'WorkFlowBtn',
  props: {
    type: {
      type: Number,
      default: 1
    },
    row: {
      type: Object,
      required: true
    }
  },
  methods: {
    show(val) {
      const status = this.row.status
      const type = this.type
      let isShow = false
      let userId = store.getters.user.id
      let isAdmin = store.getters.user.isAdmin
      if(userId == '1'){
        return true
      }
      //判断是否管理员
      if(isAdmin){
        return true
      }
      switch (val) {
        case 2:
          if ((status === 0  && this.row.createrId === userId)
            || (status === 1 && this.row.auditUserIds.indexOf(userId) != -1) && this.row.createrId === userId) {
            isShow = true
          }
          break
        case 3:
          if ((status === 2 && this.row.auditUserIds && this.row.auditUserIds.indexOf(userId) != -1) ||
              (status === 7 && this.row.auditUserIds && this.row.auditUserIds.indexOf(userId) != -1)
          ) {
            isShow = true
          }
          break
        case 4:
          if ((status === 0 && this.row.createrId === userId) || (status === 1 && this.row.auditUserIds.indexOf(userId) != -1) && this.row.createrId === userId) {
            isShow = true
          }
          break
      }
      return isShow
    },
    edit(obj) {
      this.$emit('edit', obj)
    },
    del(obj) {
      this.$emit('del', obj)
    },
    approve(obj) {
      this.$emit('approve', obj)
    },
    detail(obj) {
      this.$emit('detail', obj)
    }
  }
}
</script>

<style scoped>

</style>
